package com.quyunshuo.module.home.manager

import android.app.usage.UsageStatsManager
import android.content.Context
import android.content.Intent
import android.provider.Settings

object PermissionUtils {

    fun hasUsageStatsPermission(context: Context): Boolean {
        val appInfo = context.packageManager.getApplicationInfo(context.packageName, 0)
        val statsManager = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager
        val now = System.currentTimeMillis()
        return statsManager.queryUsageStats(
            UsageStatsManager.INTERVAL_DAILY,
            now - 1000 * 60 * 60,
            now
        ) != null
    }

    fun requestUsageStatsPermission(context: Context) {
        context.startActivity(Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS))
    }
}